home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wzun11sr.zip / UPDATELB.C < prev    next >
C/C++ Source or Header  |  1992-01-24  |  4KB  |  114 lines

  1. #include <windows.h>    /* required for all Windows applications */
  2. #include <assert.h>    /* required for all Windows applications */
  3. #include "wizunzip.h"                /* specific to this program              */
  4. #include "unzip.h"     
  5.  
  6. /* updatelb.c module of WizUnzip.
  7.  * Author: Robert A. Heath
  8.  * I, Robert Heath, place this source code module in the public domain.
  9.  */
  10.  
  11. /* Trailers are the lines just above the totals
  12.  */
  13. static char *Trailers[2] = {
  14. " ------                    -------",
  15. " ------          ------  ---                              -------"
  16. } ;
  17.  
  18. /* Update Buttons is called when an event possibly modifies the 
  19.  * number of selected items in the listbox. 
  20.  * The function reads the number of selected items. 
  21.  * A non-zero value enables relevant buttons and menu items.
  22.  * A zero value disables them.
  23.  */
  24. void
  25. UpdateButtons(HWND hWnd)
  26. {
  27. BOOL bButtonState;
  28.  
  29.     if (szFileName[0] &&
  30.         SendMessage(hWndList, LB_GETSELCOUNT, 0, 0L)) /* anything selected ? */
  31.     {
  32.         bButtonState = TRUE;
  33.     }
  34.     else
  35.     {
  36.         bButtonState = FALSE;
  37.     }
  38.     EnableWindow(hExtract, bButtonState);
  39.     EnableWindow(hDisplay, bButtonState);
  40.     EnableWindow(hTest, bButtonState);
  41.     EnableWindow(hShowComment, (BOOL)(szFileName[0] && wCommentLength ? TRUE : FALSE));
  42. }
  43.  
  44. /* Update List Box attempts to fill the list box on the parent
  45.  * window with the next "ListBoxLines" of personal data from the 
  46.  * current position in the file.
  47.  * UpdateListBox() assumes that the a record has been read in when called.
  48.  * The TotalZippedFiles variable indicates whether or not a record exists.
  49.  * The bForward parameter controls whether updating precedes forward
  50.  * or reverse.
  51.  */
  52. void
  53. UpdateListBox(HWND hWnd)
  54. {
  55.  
  56.     SetWindowText(hWndHeaderLine1, (LPSTR)Headers[wFormat][0]);
  57.     SetWindowText(hWndHeaderLine2, (LPSTR)Headers[wFormat][1]);
  58.     SetWindowText(hWndTotalLine1 , (LPSTR)Trailers[wFormat]);
  59.     SetWindowText(hWndTotalLine2 , (LPSTR)"");
  60.  
  61.     SendMessage(hWndList, LB_RESETCONTENT, 0, 0L);
  62.     TotalZippedFiles = 0;        /* assume no personal records         */
  63.      if (szFileName[0])         /* file selected ?                     */
  64.     {    /* if so -- stuff list box                */
  65.         SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L);
  66.         if (SetUpToProcessZipFile(0, 0, 
  67.                 (int)(!wFormat ? 1 : 2), 1, 0, 0, 0, 0,
  68.                             0, szFileName, NULL))
  69.             process_zipfile();    /* call into unzip.c        */
  70.  
  71.         else 
  72.             MessageBox(hMainWnd, NoMemoryMsg, NULL, 
  73.                         MB_OK|MB_ICONEXCLAMATION); 
  74.         
  75.         TakeDownFromProcessZipFile();    /* clean house    */
  76. #ifndef NEED_EARLY_REDRAW
  77.         SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
  78.         InvalidateRect(hWndList, NULL, TRUE);    /* force redraw            */
  79. #endif
  80.         TotalZippedFiles = (WORD)SendMessage(hWndList, LB_GETCOUNT, 0, 0L);
  81.         assert((int)TotalZippedFiles != LB_ERR);
  82.         if (TotalZippedFiles)    /* if anything went into listbox set to top */
  83.         {
  84. #ifdef NEED_EARLY_REDRAW
  85.             UpdateWindow(hWndList);    /* paint now!                    */
  86. #endif
  87.             SendMessage(hWndList, LB_SETTOPINDEX, 0, 0L);
  88.         }
  89. #ifdef NEED_EARLY_REDRAW
  90.         else /* no files were unarchived!                            */
  91.         {
  92.             /* Add dummy message to initialize list box then clear it
  93.              * to prevent strange problem where later calls to 
  94.              * UpdateListBox() do not result in displaying of all contents.
  95.               */
  96.             SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  97.             UpdateWindow(hWndList);    /* paint now!                    */
  98.         }
  99. #endif
  100.     }
  101. #ifdef NEED_EARLY_REDRAW
  102.     else
  103.     {
  104.         /* Add dummy message to initialize list box then clear it
  105.          * to prevent strange problem where later calls to 
  106.          * UpdateListBox() do not result in displaying of all contents.
  107.           */
  108.         SendMessage(hWndList, LB_ADDSTRING, 0, (LONG)(LPSTR)" ");
  109.         UpdateWindow(hWndList);    /* paint now!                    */
  110.     }
  111. #endif
  112.  
  113. }
  114.